{
 "nbformat": 4,
 "nbformat_minor": 0,
 "metadata": {
  "colab": {
   "provenance": [],
   "authorship_tag": "ABX9TyOKqfSVq+Brmr4ZM+kUh/HP",
   "include_colab_link": true
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3"
  },
  "language_info": {
   "name": "python"
  }
 },
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "view-in-github",
    "colab_type": "text"
   },
   "source": [
    "<a href=\"https://colab.research.google.com/github/SkywalkerDarren/chatWeb/blob/master/example.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
   ]
  },
  {
   "cell_type": "markdown",
   "source": [
    "把下面换成你自己的openai key，然后依次执行下列准备步骤\n",
    "Please replace the following with your own OpenAI API key, and language, and then execute the following preparation steps in order:"
   ],
   "metadata": {
    "id": "2rmPdzNs13ga"
   }
  },
  {
   "cell_type": "code",
   "source": [
    "open_ai_key = \"sk-xxxxxxxxxxxx\" # Your OpenAI API key\n",
    "language = \"Chinese\" # Language of the chatbot"
   ],
   "metadata": {
    "id": "roZqoNX0ubG5"
   },
   "execution_count": 8,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "%%shell\n",
    "# Ubuntu no longer distributes chromium-browser outside of snap\n",
    "#\n",
    "# Proposed solution: https://askubuntu.com/questions/1204571/how-to-install-chromium-without-snap\n",
    "\n",
    "# Add debian buster\n",
    "cat > /etc/apt/sources.list.d/debian.list <<'EOF'\n",
    "deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster.gpg] http://deb.debian.org/debian buster main\n",
    "deb [arch=amd64 signed-by=/usr/share/keyrings/debian-buster-updates.gpg] http://deb.debian.org/debian buster-updates main\n",
    "deb [arch=amd64 signed-by=/usr/share/keyrings/debian-security-buster.gpg] http://deb.debian.org/debian-security buster/updates main\n",
    "EOF\n",
    "\n",
    "# Add keys\n",
    "apt-key adv --keyserver keyserver.ubuntu.com --recv-keys DCC9EFBF77E11517\n",
    "apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 648ACFD622F3D138\n",
    "apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 112695A0E562B32A\n",
    "\n",
    "apt-key export 77E11517 | gpg --dearmour -o /usr/share/keyrings/debian-buster.gpg\n",
    "apt-key export 22F3D138 | gpg --dearmour -o /usr/share/keyrings/debian-buster-updates.gpg\n",
    "apt-key export E562B32A | gpg --dearmour -o /usr/share/keyrings/debian-security-buster.gpg\n",
    "\n",
    "# Prefer debian repo for chromium* packages only\n",
    "# Note the double-blank lines between entries\n",
    "cat > /etc/apt/preferences.d/chromium.pref << 'EOF'\n",
    "Package: *\n",
    "Pin: release a=eoan\n",
    "Pin-Priority: 500\n",
    "\n",
    "\n",
    "Package: *\n",
    "Pin: origin \"deb.debian.org\"\n",
    "Pin-Priority: 300\n",
    "\n",
    "\n",
    "Package: chromium*\n",
    "Pin: origin \"deb.debian.org\"\n",
    "Pin-Priority: 700\n",
    "EOF"
   ],
   "metadata": {
    "id": "9HBoEHPFvaDv"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "!apt-get update\n",
    "!apt-get install chromium chromium-driver\n",
    "!git clone https://github.com/SkywalkerDarren/chatWeb.git\n",
    "%cd chatWeb\n",
    "!pip3 install -r requirements.txt"
   ],
   "metadata": {
    "id": "71znqup2wrt-"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "code",
   "source": [
    "import json\n",
    "\n",
    "with open('config.example.json', 'r') as f:\n",
    "    config = json.load(f)\n",
    "\n",
    "config['open_ai_key'] = open_ai_key\n",
    "config['language'] = language\n",
    "\n",
    "with open('config.json', 'w') as f:\n",
    "    json.dump(config, f)"
   ],
   "metadata": {
    "id": "b5kT-S5rt1e6"
   },
   "execution_count": null,
   "outputs": []
  },
  {
   "cell_type": "markdown",
   "source": [
    "以上是准备步骤，准备完后运行下面这条命令即可，quit以后也可以重复运行\n",
    "The above are preparation steps, run the following command after preparation, and you can also run it again after /quit."
   ],
   "metadata": {
    "id": "yfJMbmUL1Vfp"
   }
  },
  {
   "cell_type": "code",
   "source": [
    "!python3 main.py"
   ],
   "metadata": {
    "id": "gQBKF8cxu3AY"
   },
   "execution_count": null,
   "outputs": []
  }
 ]
}
